﻿using System;
using System.Data;
using System.Collections.Generic;
using Chenxin.Lib.Hr.Entity;
namespace Chenxin.Lib.Hr.BLL
{
    /// <summary>
    /// 业务逻辑类Base_RolePermitionRelationInfo 的摘要说明。
    /// </summary>
    public class Base_RolePermitionRelationInfo
    {
        //Cache服务类
        private Chenxin.Lib.Cache.CacheService cs = new Chenxin.Lib.Cache.CacheService(Chenxin.Lib.Cache.CacheConn.xCacheConn.HR);

        public Base_RolePermitionRelationInfo()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(Guid RecordId)
        {
            return Chenxin.Lib.Hr.DAL.Base_RolePermitionRelationInfo.Exists(RecordId);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Chenxin.Lib.Hr.Entity.Base_RolePermitionRelationInfo model)
        {
            Chenxin.Lib.Hr.DAL.Base_RolePermitionRelationInfo.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Chenxin.Lib.Hr.Entity.Base_RolePermitionRelationInfo model)
        {

            Chenxin.Lib.Hr.DAL.Base_RolePermitionRelationInfo.Update(model);
            //某一角色的权限对应的键
            string strKeyRolePermits = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_ROLEPERMITS, model.RoleId.ToString());
            //删除
            cs.Delete(strKeyRolePermits);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(Guid RecordId)
        {

            Chenxin.Lib.Hr.DAL.Base_RolePermitionRelationInfo.Delete(RecordId);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void DeleteByRoleId(Guid RoleId)
        {

            Chenxin.Lib.Hr.DAL.Base_RolePermitionRelationInfo.DeleteByRoleId(RoleId);
            //某一角色的权限对应的键
            string strKeyRolePermits = string.Format(Chenxin.Lib.Cache.CacheDataType.HR_ROLEPERMITS, RoleId.ToString());
            //删除
            cs.Delete(strKeyRolePermits);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Chenxin.Lib.Hr.Entity.Base_RolePermitionRelationInfo GetModel(Guid RecordId)
        {

            return Chenxin.Lib.Hr.DAL.Base_RolePermitionRelationInfo.GetModel(RecordId);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return Chenxin.Lib.Hr.DAL.Base_RolePermitionRelationInfo.GetList(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.Hr.Entity.Base_RolePermitionRelationInfo> GetModelList(string strWhere)
        {
            DataSet ds = Chenxin.Lib.Hr.DAL.Base_RolePermitionRelationInfo.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.Hr.Entity.Base_RolePermitionRelationInfo> DataTableToList(DataTable dt)
        {
            List<Chenxin.Lib.Hr.Entity.Base_RolePermitionRelationInfo> modelList = new List<Chenxin.Lib.Hr.Entity.Base_RolePermitionRelationInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Chenxin.Lib.Hr.Entity.Base_RolePermitionRelationInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Chenxin.Lib.Hr.Entity.Base_RolePermitionRelationInfo();
                    if (dt.Rows[n]["RecordId"].ToString() != "")
                    {
                        model.RecordId = new Guid(dt.Rows[n]["RecordId"].ToString());
                    }
                    if (dt.Rows[n]["RoleId"].ToString() != "")
                    {
                        model.RoleId = new Guid(dt.Rows[n]["RoleId"].ToString());
                    }
                    if (dt.Rows[n]["PermitId"].ToString() != "")
                    {
                        model.PermitId = new Guid(dt.Rows[n]["PermitId"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

